package com.jufa_3.controller;

import com.jufa_3.common.R;
import com.jufa_3.dto.ComboCostInfo;
import com.jufa_3.dto.Rates;
import com.jufa_3.entity.CostItem;
import com.jufa_3.mapper.CostItemMapper;
import com.jufa_3.service.ComboOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/costItem")
public class CostItemController {

    @Autowired
    private ComboOrderService comboOrderService;

    @Autowired
    private CostItemMapper costItemMapper;

    @GetMapping("/getCostItems")
    public R<List<CostItem>> getCostItems(CostItem ci) {
        return R.success(costItemMapper.getCostItems(ci));
    }

    @GetMapping("/updataCostItem")
    public R<Object> updataCostItem(CostItem ci) {
        return R.success(costItemMapper.updateCostItem(ci));
    }

    @GetMapping("/getComboCostInfo")
    public R<Rates> getComboCostInfo(String openId, String costName) {
        ComboCostInfo cci = comboOrderService.getUserCombos(openId, true);
        if (cci == null){
            return R.error(4000, "套餐余额为0");
        }
        // 获取此套餐下扣费额以及直接支付额
        String comboName = cci.getComboOrderNomal().get(0).getComboName();
        Float cc = costItemMapper.getComboCostInfo(costName, comboName).getPrice();
        return R.success(new Rates(cc, cci));
    }

    @GetMapping("/getDirectPayInfo")
    public R<Float> getPayInfo(String costName) {
        return R.success(costItemMapper.getDirectPayInfo(costName));
    }

    @GetMapping("/getMinCost")
    public R<Float> getMinCost(String costName) {
        return R.success(costItemMapper.getMinCost(costName));
    }

}
